#include "TcpServer.hpp"
#include <memory>

void NetCal(Connection* conn, std::string& request)
{
    logMessage(DEBUG, "get a request: %s", request.c_str());
    // 反序列化
    Request req;
    if (!req.Deserialize(request)) return;

    // 业务处理
    Response resp = calculator(req);

    // 序列化，构建应答
    std::string package = resp.Serialize();
    package = Encode(package);

    // 交给服务器，发送
    conn->_outbuffer += package;

    // 触发写事件
    conn->_tsvr->EnableReadWrite(conn, true, true);
}

int main()
{
    std::unique_ptr<TcpServer> svr(new TcpServer());
    svr->Dispather(NetCal);
    return 0;
}